<?php
namespace Api;
use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\util\Util;

class Notice extends Api
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取系统公告
     */
    public function getNotice()
    {
        Util::appointGet();
        try{
            $Setting = $this->newController("Setting");
            $_setting = $Setting->find();
            if(empty(trim($_setting["notice"]))) throw new \PDOException("",100);
            $ReadNotice = $this->newController("ReadNotice");
            $_read_time = $ReadNotice->value("time");
            if($_read_time && $_read_time == $_setting["notice_time"]) throw new \PDOException("",100);
            Util::returns(array("code"=>0,"data"=>$_setting["notice"]));
        } catch (\PDOException $e) {
            Util::returns(array("code"=>$e->getCode()));
        }
    }

    /**
     * 阅读公告
     */
    public function read()
    {
        Util::appointPost();
        $ReadNotice = $this->newController("ReadNotice");
        if($ReadNotice->read()) {
            $_result = array("code"=>0);
        } else {
            $_result = array("code"=>103);
        }
        Util::returns($_result);
    }
}